<link href="/public/css/main.css" rel="stylesheet">
<div class='_line'></div>
<div class="_contro">
        <a href='#' onclick='javascript:history.back(-1);'>返回上一页</a>
</div>
<div class="_cut"></div>
<div class="">
    <div class="login_div">
        <div style='text-align: right'>
            <font style="color:red">
                <?php if($_GET['msg']==1){ ?>
                    两次密码不一致
                <?php }elseif($_GET['msg']==2){?>
                    验证码错误
                 <?php } ?>
            </font>
        </div>
        <form  action='/home/passport/subrepassword' method="post" id='_form'>
            <div class='form-group row'>
                <label for="exampleInputName2">手机号:</label>
                <span><?php echo $mobile;?></span>&nbsp;&nbsp;&nbsp;&nbsp;<button type="button" id='subcode' onclick="_code();" style='width:35%'>获取验证码</button>
            </div>
            <div class='form-group row'>
                <label for="exampleInputName2">验证码:</label>
                <input type="password" class="form-control" id="code" name='code' placeholder="验证码" value=""/>
            </div>
            <div class='form-group row'>
                <label for="exampleInputName2">新密码:</label>
                <input type="password" class="form-control" id="password" name='password' placeholder="6-12位密码" value=""/>
            </div>
            <div class='form-group row'>
                <label for="exampleInputName2">确认密码:</label>
                <input type="password" class="form-control" name='repassword' placeholder="6-12位密码" value=""/>
            </div>
            <div class="form-group login_sub">
                <input type="submit" class="btn btn-info" name="submit" onsubmit='_submit();' value="提交">
            </div>
        </form>
    </div>
</div>
<script type='text/javascript'>
    function _code() {
        $.ajax({url: "/home/passport/code?op=1", async: true, success: function (msg) {
                if (msg != 'true') {
                    alert(msg);
                    return false;
                }
                $("#subcode").text('60');
                $("#subcode").attr('disabled', 'disabled');
                var t = setInterval(function () {
                    var m = $("#subcode").text();
                    var str = parseInt(m) - 1;
                    if (str <= 0) {
                        str = '获取验证码';
                        $("#subcode").removeAttr('disabled');
                        clearInterval(t);
                    }
                    $("#subcode").text(str);
                }, 1000);
            }
        });
    }
    function checkcode() {
        var code = $("#code").val();
        $.ajax({url: "/home/passport/checkcode?code=" + code, async: true, success: function (msg) {
                if (msg != 'true') {
                    alert('验证码错误');
                    return false;
                }
                return true;
            }
        });
    }
    function _submit(){
        var password = $("#password").val();
        var repassword = $("#repassword").val();
        if(password.length < 6 || password.length > 12){
            alert('密码长度请在6-12位之间');
            return false;
        }
        if(password != repassword){
            alert('两次密码不一致');
            return false;
        }
        if(checkcode()==false){
            alert('验证码错误');
            return false;
        }
        $('_form').submit();
    }
</script>
